package com.naxiang.cn.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.naxiang.cn.naxiangbackcard.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 作者: 赵航
 * 创建时间: 2018/8/8 15:07
 * 描述:
 */
public class CardItemAdapter extends BaseAdapter {
    private List<ItemsBeen> mItems;
    public CardItemAdapter(List<ItemsBeen> mList) {
        this.mItems = mList;
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public ItemsBeen getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.mo_naxiangbackcard_item_layout, parent, false);
            holder.mImageView = (ImageView) convertView.findViewById(R.id.listbankicon);
            holder.mTitleText = (TextView) convertView.findViewById(R.id.titletext);
            holder.mChioce = (ImageView) convertView.findViewById(R.id.chioce);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//
//        ImageLoader imageLoader = ImageLoader.getInstance();
//        imageLoader.init(ImageLoaderConfiguration.createDefault(parent.getContext()));
//        //添加图片加载监听
//        final ViewHolder finalHolder = holder;
//        imageLoader.displayImage(mItems.get(position).getUrl(), holder.mImageView, new ImageLoadingListener() {
//            @Override
//            public void onLoadingStarted(String s, View view) {
//            }
//            @Override
//            public void onLoadingFailed(String s, View view, FailReason failReason) {
//                finalHolder.mTitleText.setVisibility(VISIBLE);
//                finalHolder.mTitleText.setText("加载失败");
//            }
//
//            @Override
//            public void onLoadingComplete(String s, View view, Bitmap bitmap) {
//                finalHolder.mTitleText.setVisibility(INVISIBLE);
//            }
//            @Override
//            public void onLoadingCancelled(String s, View view) {
//            }
//        });



        Picasso.with(parent.getContext()).load(mItems.get(position).getUrl())
                //占位图，图片加载出来之前显示的默认图片
                .placeholder(R.drawable.loading)
                //错误图，图片加载出错时显示的图片
                .error(R.drawable.loading)
                .into(holder.mImageView);
        holder.mTitleText.setText(mItems.get(position).getText());
        System.out.println("标题是：=="+mItems.get(position).getText());
        holder.mChioce.setSelected(mItems.get(position).isSelect());
        return convertView;
    }

    public class ViewHolder {
        ImageView mImageView;
        TextView  mTitleText;
        TextView  mLoadingText;
        ImageView mChioce;
    }
}
